package edu.nf.admin.controller.admin;

import edu.nf.waimai.dao.admin.impl.AdminShopDaoImpl;
import edu.nf.waimai.model.shop.Shop;
import org.nf.web.annotation.Model;
import org.nf.web.annotation.RequestMapping;
import org.nf.web.annotation.RequestParam;
import org.nf.web.servlet.View;
import org.nf.web.servlet.view.JsonView;

import java.util.List;

/**
 * @Date 2023-09-12
 * @Author qiu
 * 商家信息
 */
public class ShopInfoController extends BaseController {

    /**
     * 商家信息 -- 管理员端
     *
     * @return
     */
    @RequestMapping("/shop/shopInfo")
    public View getAllShop() {
        List<Shop> allShop = new AdminShopDaoImpl().getAllShop();
        return new JsonView(success(allShop));
    }


    /**
     * 商家修改
     *
     * @param shop
     * @return
     */
    @RequestMapping("/shop/updateShop")
    public View updateUser(@Model Shop shop) {
        int i = new AdminShopDaoImpl().updateShop(shop);
        return new JsonView(success(200, "修改成功", i));
    }

    /**
     * 删除商家
     *
     * @param sid
     * @return
     */
    @RequestMapping("/shop/deleteShop")
    public View deleteUser(@RequestParam("shopId") int sid) {
        int i = new AdminShopDaoImpl().deleteShop(sid);
        return new JsonView(success(200, "删除成功", i));
    }

    /**
     * 添加商家
     *
     * @param shop
     * @return
     */
    @RequestMapping("/shop/addShop")
    public View addUser(@Model Shop shop) {
        int i = new AdminShopDaoImpl().addShop(shop);
        return new JsonView(success(200, "添加成功", i));
    }

    /**
     * 查询商家订单信息
     *
     * @return
     */
    @RequestMapping("/shop/getShop")
    public View getShop() {
        List<Shop> user = new AdminShopDaoImpl().getShop();
        return new JsonView(success(user));
    }

}
